package com.example.myviewpagerdemo;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class WelcomeAct extends Activity {
    private static final int TIME=2000;
    private static final int GO_HOME=1000;
    private static final int GO_GUIDE =1001;

    //

    private boolean isFirstIn =false; //    用于判断是哪个消息

    //
    private Handler mHandle = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            switch (msg.what){
                case GO_HOME:
                    goHome();
                    break;
                default:
                    goGuild();
                    break;
            }
        }
    };

    //
    private void init(){
        SharedPreferences preferences = getSharedPreferences("jike",MODE_PRIVATE); // 获取对像
        isFirstIn=preferences.getBoolean("isFirstIn",true); // 获取里面的值（判读有没有，有就获取）
        if(!isFirstIn){
            mHandle.sendEmptyMessageDelayed(GO_HOME,TIME); // 发送进入主界面的消息
        }else{
            mHandle.sendEmptyMessageDelayed(GO_GUIDE,TIME); //
            //进入过引导界面后，存储该值
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("isFirstIn",false); // 存入数据
            editor.commit();// 提交
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);

        //保证是首次进去时调用
        init();
    }

    // 实现跳转
    private void goHome(){
        Intent i = new Intent(WelcomeAct.this,MainActivity.class);
        startActivity(i);
        finish();
    }

    private void goGuild(){
        Intent i = new Intent(WelcomeAct.this,Guide.class);
        startActivity(i);
        finish();
    }



}
